﻿using System.Collections.Generic;
using System.Threading.Tasks;
using WeChat.BaseInterface;
using WeChat.Dto.Users;
using WeChat.Entity;
using WeChat.IRepository;
using WeChat.IService;

namespace WeChat.Service
{
    /// <summary>
    /// 用户服务 实现
    /// </summary>
    public class UsersService : IUsersService
    {
        private readonly IUsersRepository _usersRepository;

        public UsersService(IUsersRepository usersRepository)
        {
            _usersRepository = usersRepository;
        }

        /// <summary>
        /// 创建用户
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        public async Task<bool> CreateAsync(CreateUsersInput input)
        {
            var dbUser = input.MapToExt<WeChatUsers>();
            await _usersRepository.CreateAsync(dbUser);
            return dbUser.Id > 0;
        }

        /// <summary>
        /// 获取所有未删除
        /// </summary>
        /// <returns></returns>
        public async Task<List<GetAllUsersDto>> GetAllUserAsync()
        {
            var dbList = await _usersRepository.GetListAsync(a => a.IsDelete == false);
            return dbList.MapToExt<List<GetAllUsersDto>>();
        }
    }
}
